﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.Collections.Generic;
using Hsinchu.Utility;

public partial class Admin_AdminUser_GlobalConfiguration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }


    /// <summary>
    /// 初始化载入
    /// </summary>
    void InitLoad()
    {

    }


    /// <summary>
    /// 提交系统信息事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifySystemSetup_Click(object sender, EventArgs e)
    {
        //获得全局配置文件名
        string globalFileName = Server.MapPath("~/") + "Config/Global.xml";
        Dictionary<string, string> xmlNode = new Dictionary<string, string>();
        if (this.rbtnOpen.Checked)
        {
            xmlNode.Add("UrlRewrite", "开启");
        }
        if (this.rbtnOpen.Checked)
        {
            xmlNode.Add("UrlRewrite", "关闭");
        }
        xmlNode.Add("ReciveAddressMax", this.txtReciveAddress.Text);
        xmlNode.Add("MaximumAttachmentSize", this.txtMaximumAttachment.Text);
        xmlNode.Add("CacheSurvival", this.txtCacheSurvival.Text);
        xmlNode.Add("GoodsDefaultPic", this.fupGoodsDefaultPic.FileName);
        //上传文件
        if (this.fupGoodsDefaultPic.FileName.Length > 0)
        {
            //获得附件文件名
            string _filename = this.fupGoodsDefaultPic.FileName;
            //判断是否存在
            if (System.IO.File.Exists(Server.MapPath("~/") + "Image/" + _filename))
            {
                System.IO.File.Delete(Server.MapPath("~/") + "Image/" + _filename);
            }
            else
            {
                //弹出对话框报已存在！
            }
            this.fupGoodsDefaultPic.SaveAs(Server.MapPath("~/") + "Image/" + _filename);
            //写入配置文件
            if (XMLHelper.InsertNode(globalFileName, "//SystemSetup", xmlNode))
            {
                //弹出对话框确认
            }
        }
        else
        {
            //弹出对话框报错！
        }
    }

    /// <summary>
    /// 系统设置按钮重置
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnResetSystemSetup_Click(object sender, EventArgs e)
    {
        this.txtReciveAddress.Text = "";
        this.txtMaximumAttachment.Text = "";
        this.txtCacheSurvival.Text = "";
        this.rbtnOpen.Checked = true;
    }



    /// <summary>
    /// 提交基本信息事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifyBaseInfomation_Click(object sender, EventArgs e)
    {
        //获得全局配置文件名
        string globalFileName = Server.MapPath("~/") + "Config/Global.xml";
        Dictionary<string, string> xmlNode = new Dictionary<string, string>();
        if (this.rbtnMallOpen.Checked)
        {
            xmlNode.Add("MallStatus", "开启");
        }
        if (this.rbtnMallClose.Checked)
        {
            xmlNode.Add("MallStatus", "关闭");
        }
        xmlNode.Add("MallName", this.txtMallName.Text);
        xmlNode.Add("MallTitle", this.txtMallTitle.Text);
        xmlNode.Add("MallKeyWords", this.txtMallKeyWords.Text);
        xmlNode.Add("MallDescription", this.txtMallDescription.Text);
        xmlNode.Add("MallLogo", this.fupLogo.FileName);
        xmlNode.Add("ICPCertificateNo", this.txtICPCertificateNo.Text);
        xmlNode.Add("MallLocation", this.txtMallLocation.Text);
        xmlNode.Add("MallFullAddress", this.txtMallAddress.Text);
        xmlNode.Add("MallPostCode", this.txtMallPostCode.Text);
        xmlNode.Add("MallTel", this.txtTel.Text);
        xmlNode.Add("MallEmail", this.txtEmail.Text);
        xmlNode.Add("ProductsDisplayedPerPage", this.txtProductNumPerPage.Text);
        xmlNode.Add("CloseReason", this.txtCloseReason.Text);
        xmlNode.Add("TopSearches", this.txtTopSearch.Text);
        //上传文件
        if (this.fupGoodsDefaultPic.FileName.Length > 0)
        {
            //获得附件文件名
            string _filename = this.fupGoodsDefaultPic.FileName;
            //判断是否存在
            if (System.IO.File.Exists(Server.MapPath("~/") + "Image/" + _filename))
            {
                System.IO.File.Delete(Server.MapPath("~/") + "Image/" + _filename);
            }
            else
            {
                //弹出对话框报已存在！
            }
            this.fupGoodsDefaultPic.SaveAs(Server.MapPath("~/") + "Image/" + _filename);
            //写入配置文件
            if (XMLHelper.InsertNode(globalFileName, "//BaseInfomation", xmlNode))
            {
                //弹出对话框确认
            }
        }
        else
        {
            //弹出对话框报错！
        }
    }


    /// <summary>
    /// 基本信息重置事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnResetBaseInfomation_Click(object sender, EventArgs e)
    {
        this.txtMallName.Text = "";
        this.txtMallTitle.Text = "";
        this.txtMallKeyWords.Text = "";
        this.txtMallDescription.Text = "";
        this.txtICPCertificateNo.Text = "";
        this.txtMallLocation.Text = "";
        this.txtMallAddress.Text = "";
        this.txtMallPostCode.Text = "";
        this.txtTel.Text = "";
        this.txtEmail.Text = "";
        this.txtProductNumPerPage.Text = "";
        this.txtCloseReason.Text = "";
        this.txtTopSearch.Text = "";
    }

    /// <summary>
    /// 提交Server设置事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnModifyServer_Click(object sender, EventArgs e)
    {
        //获得全局配置文件名
        string globalFileName = Server.MapPath("~/") + "Config/Global.xml";
        Dictionary<string, string> xmlNode = new Dictionary<string, string>();

        xmlNode.Add("ServerIP", this.txtServerIP.Text);
        xmlNode.Add("ServerPort", this.txtServerPort.Text);
        xmlNode.Add("EmailServer", this.txtEmailServer.Text);
        xmlNode.Add("EmailAccount", this.txtEmailAccount.Text);
        xmlNode.Add("EmailPassWord", this.txtEmailPassWord.Text);
        xmlNode.Add("EmailCoding", this.txtCode.Text);
        xmlNode.Add("TestEmailServer", this.txtTestEmailServer.Text);
        //写入配置文件
        if (XMLHelper.InsertNode(globalFileName, "//Server", xmlNode))
        {
            //弹出对话框确认
        }

    }

    /// <summary>
    /// Server设置重置
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnResetServer_Click(object sender, EventArgs e)
    {
        this.txtServerIP.Text = "";
        this.txtServerPort.Text= "";
        this.txtEmailServer.Text= "";
        this.txtEmailAccount.Text= "";
        this.txtEmailPassWord.Text= "";
        this.txtCode.Text= "";
        this.txtTestEmailServer.Text = "";
    }



}
